<template>
	<view>
		<button type="default" @tap="upload">上传照片</button>
		<view class="wrap">
			<image style="width: 100%; height: 200px;" mode="scaleToFill" :src="src">
			</image>
			<progress v-show="pg>0" :percent="pg" show-info stroke-width="3" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				src: "",
				pg:0
			}
		},
		methods: {
			upload() {
				let that = this;
				uni.chooseImage({
						count: 1,
						async success(res) {
							if (res.tempFilePaths.length > 0) {
								let filePath = res.tempFilePaths[0];
								uniCloud.uploadFile({
									filePath: filePath,
									cloudPath: 'a.jpg',
									onUploadProgress: function(progressEvent) {
										var percentCompleted = Math.round(
											(progressEvent.loaded * 100) / progressEvent.total
										);
										that.pg = percentCompleted;
										console.log("percentCompleted",percentCompleted);
									},
									success:(res) =>{
										uni.showToast({
											title: '上传成功',
											duration: 2000
										});
										that.src = res.filePath;
									},
									fail() {},
									complete() {}
								});
							}
						}
				});
		}
	}
	}
</script>

<style lang="scss" scoped>
.wrap{
	margin-top: 24rpx;
}
</style>
